project(Demo)

set(QT_CPP_ROOTDIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_PREFIX_PATH "${QT_CPP_ROOTDIR}/3rdParty/qt")
set(Qt5_DIR "${QT_CPP_ROOTDIR}/3rdParty/qt/lib/cmake/lib")
set(CMAKE_AUTOMOC ON)

find_package(Qt5 COMPONENTS Widgets Core Gui REQUIRED)

set(WEBKIT_ZIP "${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/qt/bin/Qt5WebKit.rar")
set(WEBKIT_DLL "${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/qt/bin/Qt5WebKit.dll")
set(DESTINATION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/qt/bin/")

if(NOT EXISTS ${WEBKIT_DLL})
    message(STATUS "unzip ${WEBKIT_ZIP} 到 ${DESTINATION_DIR}")
    execute_process(
        COMMAND ${CMAKE_COMMAND} -E tar xf ${WEBKIT_ZIP}
        WORKING_DIRECTORY ${DESTINATION_DIR}
    )
endif()

set(LIBS glfw3)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/opengl/configuration/root_directory.h.in 
                ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/opengl/configuration/root_directory.h)
                
add_library(STB_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/opengl/src/stb_image.cpp")
target_include_directories(STB_IMAGE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/opengl/include)
set(LIBS ${LIBS} STB_IMAGE)

add_library(GLAD "${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/opengl/src/glad.c")
target_include_directories(GLAD PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty/opengl/include)
set(LIBS ${LIBS} GLAD)


set(PLUGIN_DIR "${QT_CPP_ROOTDIR}/3rdParty/qt/plugins")
file(GLOB PLUGIN_SUBDIRECTORIES RELATIVE "${PLUGIN_DIR}" "${PLUGIN_DIR}/*")
foreach(subdirectory ${PLUGIN_SUBDIRECTORIES})
    file(COPY "${PLUGIN_DIR}/${subdirectory}" DESTINATION "${CMAKE_BINARY_DIR}/bin/")
endforeach()

add_subdirectory(code)
